<?php
/**
 * Created by PhpStorm.
 * User: yadongw
 * Date: 15-5-26
 * Time: 下午7:46
 */
use UcxApiSdk\Client;
include 'common.php';

$client = new Client();
$client->setAccessToken($_COOKIE['ucx_access_token']);
$documentResource = $client->getDocument();
//$doc_id = $_GET['did'];
//$document = $documentResource->find($doc_id);
if($_POST){
	move_uploaded_file($_FILES['DocumentPublishForm']['tmp_name']['fileUploaded'], $_FILES['DocumentPublishForm']['tmp_name']['fileUploaded'].'.pdf');
	try{
		$document = $documentResource->upload(
			$_FILES['DocumentPublishForm']['tmp_name']['fileUploaded'].'.pdf',
			$_POST['DocumentPublishForm']['name'],
			$_POST['DocumentPublishForm']['description'],
			$_GET['lid']
		);
		header("location:index.php");
	}catch (\Exception $e){
		echo "Error: " . $e->getMessage();
	}
}
?>
<html>
<head>
	<link href="../static/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<script type="text/javascript" src="../static/jquery.min.js"></script>
	<script type="text/javascript" src="../static/bootstrap/js/bootstrap.min.js"></script>

</head>
<body>
<h2 class="webform-title">Upload Document</h2>
<form id="upload-document" class="form-horizontal webform-box form-horizontal" method="post" enctype="multipart/form-data">
	<div class="form-group file-label-input field-documentpublishform-fileuploaded required">
		<label class="control-label col-md-4" for="documentpublishform-fileuploaded">Choose a PDF *</label>
		<div class="col-md-6"><input type="hidden" name="DocumentPublishForm[fileUploaded]" value=""><input type="file" id="documentpublishform-fileuploaded" name="DocumentPublishForm[fileUploaded]" accept="application/pdf">

			<div class="help-block"></div></div>
	</div>		<div class="form-group field-documentpublishform-name required">
		<label class="control-label col-md-4" for="documentpublishform-name">Name *</label>
		<div class="col-md-6"><input type="text" id="documentpublishform-name" class="form-control" name="DocumentPublishForm[name]">

			<div class="help-block"></div></div>
	</div>		<div class="form-group field-documentpublishform-description">
		<label class="control-label col-md-4" for="documentpublishform-description">Description</label>
		<div class="col-md-6"><textarea id="documentpublishform-description" class="form-control" name="DocumentPublishForm[description]"></textarea>

			<div class="help-block"></div></div>
	</div>
	<div class="form-group">
		<div class="col-lg-offset-4 col-lg-8">
			<button type="submit" class="btn btn-primary">Upload</button>			</div>
	</div>
</form>
</body>
</html>